home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / Memory / PlatfMem.h < prev   
Encoding:
C/C++ Source or Header  |  1997-02-13  |  3.7 KB  |  144 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        PlatfMem.h
  3.  
  4.     Contains:    Platform layer interfaces
  5.  
  6.     Owned by:    Jens Alfke
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.     
  12.          <5>     10/9/96    JP        1394963: Fixed for 68K
  13.          <4>     9/19/96    DH        Task: low memory changes, 1377922, 1377888.
  14.                                     Added/modified thresholds for low/out-of
  15.                                     memory.
  16.          <3>     9/13/96    jpa        1371387: Speed optimizations.
  17.  
  18.     To Do:
  19.     In Progress:
  20.         
  21. */
  22.  
  23. #ifndef _PLATFMEM_
  24. #define _PLATFMEM_
  25.  
  26. #ifndef _MEMCNFIG_
  27. #include "MemCnfig.h"
  28. #endif
  29.  
  30. #ifndef _MEMMGR_
  31. #include <MemMgr.h>
  32. #endif
  33.  
  34. #include <stddef.h>
  35.  
  36. #ifndef __MEMORY__
  37. #include <Memory.h>
  38. #endif
  39.  
  40.  
  41. //========================================================================================
  42. // Defines
  43. //========================================================================================
  44.  
  45. #ifndef __MWERKS__
  46.     #define _FIL_ ""            /* MPW puts entire pathnames in; yuk! */
  47. #else
  48.     #define _FIL_ __FILE__
  49. #endif
  50.  
  51. #define MM_ASSERT(condition)    \
  52.     if(!MM_DEBUG || (condition)) ; else MM_ASSERT_FAILED( #condition, _FIL_ )
  53.  
  54. #define MM_WARN    \
  55.     if(!MM_DEBUG) ; else MM_SHOW_WARNING
  56.  
  57. #define MM_WARN_COALESCE \
  58.     if(!MM_DEBUG_COALESCE) ; else MM_SHOW_WARNING
  59.  
  60. #define MM_PRINTING    0        // Set to 1 to enable MM_PRINT
  61.  
  62. #define MM_PRINT if( !MM_PRINTING ) ; else somPrintf
  63.  
  64.  
  65. //========================================================================================
  66. // Types
  67. //========================================================================================
  68.  
  69. typedef unsigned long    MMULong;
  70.  
  71. typedef unsigned long    mmboolean;
  72. // Better to use 32-bit booleans for code optimization. Can't change MMBoolean since it's
  73. // in the public API, but we can use this new type internally.
  74.  
  75. #ifdef __xlC
  76. typedef unsigned long SIZE_T;
  77. #else
  78. typedef size_t SIZE_T;
  79. #endif
  80.  
  81. typedef unsigned long ODBytePtr;
  82. typedef unsigned long ODBlockSize;
  83.  
  84.  
  85.  
  86.  
  87. //========================================================================================
  88. // Constants
  89. //========================================================================================
  90.  
  91. const mmboolean kMMFalse = 0;
  92. const mmboolean kMMTrue  = 1;
  93.  
  94. #define            kMMNULL        (0)
  95.  
  96. const size_t    kPlatformMinFreeSpace    = 64 * 1024;    // Leave this much free.
  97. const size_t    kPlatformMinContigSpace    = 32 * 1024;    // Leave this size block available
  98. // Free space is low. Allocations restricted.
  99. const size_t    kPlatformLowTotalSpace    = 128 * 1024;    
  100. const size_t    kPlatformLowContigSpace    = 64 * 1024;    
  101. // Fraction of free space allowed to be allocated when space is low
  102. const size_t    kMinFreeRatio            = 1/8;             
  103.  
  104.  
  105. //========================================================================================
  106. // Global function declarations
  107. //========================================================================================
  108.  
  109. // Declare somPrintf w/o having to include all those SOM headers:
  110. #if PRAGMA_IMPORT_SUPPORTED
  111. #pragma import on
  112. #endif
  113. extern "C" int somPrintf (const char * fmt, ...);        // From <som.xh>
  114. #if PRAGMA_IMPORT_SUPPORTED
  115. #pragma import off
  116. #endif
  117.  
  118. void PlatformZapMem( void *start, size_t size, MMULong value );
  119. void *PlatformAllocateBlock(size_t size, MMHeapLocation);
  120. void PlatformFreeBlock(void *ptr);
  121.  
  122. void MM_ASSERT_FAILED(const char *cond, const char *fil);
  123. void MM_SHOW_WARNING(const char *msg, ...);
  124.  
  125. //----------------------------------------------------------------------------------------
  126. // PlatformCopyMemory
  127. //----------------------------------------------------------------------------------------
  128.  
  129. inline void PlatformCopyMemory(void *source, void *destination, size_t length)
  130. {
  131.     BlockMoveData(source, destination, (Size) length);
  132. }
  133.  
  134. #if MM_DEBUG
  135.  
  136. #define LOWEST_POSSIBLE_ADDRESS()    ((void*) &SystemZone()->heapData)
  137. #define HIGHEST_POSSIBLE_ADDRESS()    ((void*) gTotalMemory)
  138.  
  139. extern size_t gTotalMemory;
  140.  
  141. #endif
  142.  
  143. #endif
  144.